package de.jmda.gen.java.impl;

import static de.jmda.util.StringUtil.sb;
import de.jmda.gen.GeneratorException;
import de.jmda.gen.impl.DefaultGenerator;
import de.jmda.gen.java.ExtendsClauseGenerator;
import de.jmda.util.StringUtil;

/**
 * @author roger.jmda@gmail.com
 */
public class DefaultExtendsClauseGenerator
		extends DefaultGenerator
		implements ExtendsClauseGenerator
{
	public DefaultExtendsClauseGenerator()
  {
	  super();
  }

	public DefaultExtendsClauseGenerator(String input)
  {
	  super(input);
  }

	@Override
  public StringBuffer generate() throws GeneratorException
  {
		StringBuffer result = super.generate();
		
		if (false == StringUtil.isBlank(result))
		{
			String prefix = "extends ";

			if (false == StringUtil.startsWith(result, prefix))
			{
				result = sb(prefix).append(result);
			}
		}
		
		return result;
  }

	@Override
  public StringBuffer getExtendsClause() throws GeneratorException
  {
	  return generate();
  }

	@Override
  public void setExtendsClause(StringBuffer extendsClause)
  {
		setOutput(extendsClause);
  }

	@Override
  public void setExtendsClause(String extendsClause)
  {
		setExtendsClause(sb(extendsClause));
  }
}